package 回溯;

import java.util.LinkedList;
import java.util.List;

public class Solution10 {

    public List<List<Integer>> findSubsequences(int[] nums) {
        dfs(0, new LinkedList<>(), nums);
        return res;
    }

    List<List<Integer>> res = new LinkedList<>();

    public void dfs(int index, LinkedList<Integer> path, int[] nums) {
        if (path.size() >= 2) {
            res.add(new LinkedList<>(path));
        }

        int[] used = new int[210];
        for (int i = index; i < nums.length; i++) {
            if ((path.size() > 0 && nums[i] < path.getLast()) || (used[nums[i] + 100] != 0)) continue;
            used[nums[i] + 100] = 1;
            path.addLast(nums[i]);
            dfs(i + 1, path, nums);
            path.removeLast();
        }
    }

}
